<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <p>ES2017标准引入了async函数，使得异步操作变得更加方便
        <br>async函数可以将异步操作变为同步操作
    </p>

    <script>
    /*    function print(){
            //定时器是异步的
            setTimeout(()=>{
                console.log("定时器");
                
            },10)
            console.log("Hello");
            
        }
        print();//Hello 定时器
    */

    //用async来解决上面那个先打印Hello 后打印定时器的问腿
        function timeout(ms){
            //resolve是一个函数
            const promise = new Promise((resolve,reject)=>{
                setTimeout(function(){
                    console.log("定时器");
                    resolve();
                    
                },ms)
            })
            return promise;

        }

        async function asyncPrint(ms,value){
            //把具有异步操作的代码前面放入：await
            await timeout(ms);
            console.log(value);
            
        }
        asyncPrint(100,"Hello");

    </script>

</body>
</html>